//
//  UIButton+Extension.swift
//  Weibo3
//
//  Created by xxy on 16/5/26.
//  Copyright © 2016年 xxy. All rights reserved.
//


import UIKit
// MARK: - 遍历构造函数
extension UIButton{
    /// 遍历构造函数
    ///
    /// - parameter imageName: imageName
    /// - parameter backImage: backImage
    ///
    /// - returns: UIButton
    convenience init(imageName:String, backImage:String?){
        self.init()
    setImage(UIImage(named: imageName), forState: .Normal)
    setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        if let backImage = backImage {
              setBackgroundImage(UIImage(named: backImage), forState: .Normal)
        setBackgroundImage(UIImage(named: backImage + "_highlighted"), forState: .Highlighted)

        }
          sizeToFit()
    }
    
    /// 便利构造函数
    ///
    /// - parameter title:      title
    /// - parameter titleColor: titleColor
    /// - parameter backImage:  backImage
    ///
    /// - returns: UIButton
    convenience init(title:String ,titleColor:UIColor ,backImage: String){
        self.init()
     setBackgroundImage(UIImage(named:backImage), forState: .Normal)
       setTitle(title, forState:  .Normal)
       setTitleColor(titleColor, forState: .Normal)
      setTitleColor(UIColor.whiteColor(), forState: .Highlighted)
        
    }
    
    /// 便利构造函数
    ///
    /// - parameter title:     title
    /// - parameter color:     color
    /// - parameter fontSize:  字体大小
    /// - parameter imageName: 图像名称
    ///
    /// - returns: UIButton
    convenience init(title: String, fontSize: CGFloat = 14, color: UIColor = UIColor.darkGrayColor(), imageName: String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()
    }
    
}